<?php 
include("includes/code.php");

if (isset($_GET['id'])) { $id= $_GET['id']; }

$title = CART;

///// headerni olamiz
include("includes/header.php"); 

// Process actions
$cart = $_SESSION['cart'];
$action = $_GET['action'];

switch ($action) {
	case 'add':
		if ($cart) {
			$cart .= ','.$_GET['id'];
		} else {
			$cart = $_GET['id'];
		}
		break;
	case 'delete':
		if ($cart) {
			$items = explode(',',$cart);
			$newcart = '';
			foreach ($items as $item) {
				if ($_GET['id'] != $item) {
					if ($newcart != '') {
						$newcart .= ','.$item;
					} else {
						$newcart = $item;
					}
				}
			}
			$cart = $newcart;
		}
		break;
	case 'update':
	if ($cart) {
		$newcart = '';
		foreach ($_POST as $key=>$value) {
			if (stristr($key,'qty')) {
				$id = str_replace('qty','',$key);
				$items = ($newcart != '') ? explode(',',$newcart) : explode(',',$cart);
				$newcart = '';
				foreach ($items as $item) {
					if ($id != $item) {
						if ($newcart != '') {
							$newcart .= ','.$item;
						} else {
							$newcart = $item;
						}
					}
				}
				for ($i=1;$i<=$value;$i++) {
					if ($newcart != '') {
						$newcart .= ','.$id;
					} else {
						$newcart = $id;
					}
				}
			}
		}
	}
	$cart = $newcart;
	break;
}
$_SESSION['cart'] = $cart;
?>
<!-- content and sidebar -->
<div id="main">
<table class="main_table" cellspacing="0" cellpadding="0">
  <tr valign="top">
    <td class="left_col">
<!-- ------------- left start ------------- -->
<?php include("includes/left.php"); ?>
    
<!-- ----------------- left finish ---------------- -->
    </td>
    <td>
<div class="content">
<!-- content start -->

<h4 class="sarlavha"><?php echo $lang['cart']; ?></h4>

<!-- karzina jadval start -->
<div class="batafsil">
<?php
echo showCart();
?>
<br />

<p style="font-size:18px; float:right">
<img src="themes/default/img/money.png" align="absmiddle" /> <a href="buy_cart.php"><?php echo PURCHASE; ?></a></p>
<p style="font-size:18px;"><a href="index.php"><?php echo BUY_AGAIN; ?></a></p>
<hr style="border:1px solid #999999; clear:both" />

</div>
<!-- karzina jadval finish // -->

<!-- content finish -->
</div>
    </td>
    <td class="right_col">
<!-- -------- right start ----------- -->
<?php include("includes/right.php"); ?>
<!-- --------- right finish ------- -->
    </td>
  </tr>
</table>

</div>
<!-- content and sidebar finish -->

</div>
<!-- main container finish -->
<?php include("includes/footer.php"); ?>